﻿using SmartRS.com.vn.smartrs.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NHibernate;

namespace SmartRS.com.vn.smartrs.dao
{
    public class DeskDao : BaseDao<Desk>
    {
        private static DeskDao _deskDao = new DeskDao();

        public static String TABLE_NAME = "Desk";
        public static String DESK_ID = "deskId";
        public static String DESK_NAME = "deskName";
        public static String STATUS = "status";

        private DeskDao()
        { }

        public static DeskDao getInstance()
        {
            return _deskDao;
        }

        public Desk getDeskById(long deskId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                try
                {
                    var result = session.QueryOver<Desk>().Where(x => x.deskId == deskId && x.deteleFlag == false).List<Desk>();
                    if (result != null && result[0] != null)
                    {
                        return result[0];
                    }
                    return new Desk();
                }
                catch (Exception ex)
                {
                    throw new Exception("getDeskById happened error: " + ex.Message);
                }
            }
        }

        public List<Desk> getListDeskByHallId(long hallId)
        {
            using (ISession session = NHibernateHelper.OpenSession())
            {
                try
                {
                    var result = session.QueryOver<Desk>().Where(x => x.hall.hallId == hallId && x.deteleFlag == false).OrderBy(x => x.deskId).Asc.List<Desk>();

                    return result.ToList() ?? new List<Desk>();
                }
                catch (Exception ex)
                {
                    throw new Exception("getListDeskByHallId happened error: " + ex.Message);
                }
            }
        }
    }
}
